﻿Imports System.Data.OleDb
Public Class AddDiscussion
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    End Sub

    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
        Dim myGUID As New System.Guid
        myGUID = Guid.NewGuid()
        Dim newFileName = myGUID.ToString() + ".jpg"

        If f_mainpic.HasFile Then
            f_mainpic.SaveAs(Request.MapPath("Picture") & "/" & newFileName)
        End If
        Dim oleDbConn As New OleDb.OleDbConnection(ConfigurationManager.ConnectionStrings("CoinsConn").ConnectionString)
        Dim SqlString As String = "INSERT INTO Coins(Picture,Category,Title,Availability,Description,Condition,WebPage) VALUES (@f1,@f2,@f3,@f4,@f5,@f6,@f7)"
        Dim cmd As New OleDbCommand(SqlString, oleDbConn)
        oleDbConn.Open()
        cmd.Parameters.AddWithValue("@f1", "Picture/" & newFileName)
        cmd.Parameters.AddWithValue("@f2", tb_category.Text)
        cmd.Parameters.AddWithValue("@f3", tb_title.Text)
        cmd.Parameters.AddWithValue("@f4", tb_availability.Text)
        cmd.Parameters.AddWithValue("@f5", tb_desciption.Text)
        cmd.Parameters.AddWithValue("@f6", tb_condition.Text)
        cmd.Parameters.AddWithValue("@f7", tb_webpage.Text)
        cmd.ExecuteNonQuery()
        oleDbConn.Close()
        Response.Redirect("AddConfirm.aspx")
    End Sub
End Class